package com.czhappy.huans.controller;

import com.czhappy.huans.entity.User;
import com.czhappy.huans.excel.ExcelUtils;
import com.czhappy.huans.exception.Result;
import com.czhappy.huans.exception.ResultUtil;
import com.czhappy.huans.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.List;

@RestController
@RequestMapping("/tbUser")
public class TbUserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/updateUser", method = RequestMethod.POST)
    private Result updateUser() throws Exception {
        File file = new File("F:\\others\\kqbm0701.xlsx");
        List<List<Object>> list = ExcelUtils.readExcel(file);
        if(list!=null && list.size()>1) {
            for (int i = 1; i < list.size(); i++) {
                User user = new User();
                user.setUserName((String) list.get(i).get(0));
                user.setKqCode((String) list.get(i).get(1));
                user.setType(1);
                userService.addUser(user);
            }
        }else{
            return ResultUtil.error(0, "没有记录");
        }
        return ResultUtil.success();
    }
}
